package com.mars.tukuan.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.mars.base.common.base.BaseController;
import com.mars.base.common.base.BaseResult;
import com.mars.base.common.exception.AppException;
import com.mars.base.common.utils.Paginator;
import com.mars.sso.client.filter.UserHolder;
import com.mars.tukuan.entity.CarRepairLog;
import com.mars.tukuan.rpc.api.CarRepairLogService;

@RestController
@RequestMapping("/api/tukuan/car/repair_log")
public class CarRepairLogController extends BaseController {

	@Autowired
	private CarRepairLogService service;
	

	@PostMapping(value = "/add")
	public Object add(@RequestBody CarRepairLog entity) {
		try {
			entity.setOperatorName(UserHolder.getUser().getRealName());
			this.service.insertSelective(entity);
		} catch (Exception e) {
			return BaseResult.addFailed();
		}
		return BaseResult.addOk();
	}

	@GetMapping(value = "/delete/{ids}")
	public Object delete(@PathVariable String ids) {
		try {
			this.service.deleteByIds(ids);
		} catch (Exception e) {
			return BaseResult.deleteFailed();
		}
		return BaseResult.deleteOk();
	}

	@PostMapping(value = "/update")
	public Object update(@RequestBody CarRepairLog entity) {
		try {
			entity.setOperatorName(UserHolder.getUser().getRealName());
			this.service.updateSelective(entity);
		} catch (Exception e) {
			return BaseResult.updateFailed();
		}
		return BaseResult.updateOk();
	}

	@GetMapping(value = "/get/{id}")
	public CarRepairLog get(@PathVariable Long id) {
		return this.service.selectById(id);
	}
	
	@GetMapping(value = "/list")
	public Object list(CarRepairLog entity) {
		try {
			return  this.service.selectPage(new Paginator(request), entity) ;
		} catch (AppException e) {
			return BaseResult.loadFailed();
		}
	}
	
}
